package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.GridAccount;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GridCmdTemplates;
import com.ruoyi.system.service.IGridCmdTemplatesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模板管理Controller
 * 
 * @author ruoyi
 * @date 2022-01-05
 */
@RestController
@RequestMapping("/system/templates")
public class GridCmdTemplatesController extends BaseController
{
    @Autowired
    private IGridCmdTemplatesService gridCmdTemplatesService;

    /**
     * 查询模板管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:templates:list')")
    @GetMapping("/list")
    public TableDataInfo list(GridCmdTemplates gridCmdTemplates)
    {
        startPage();
        List<GridCmdTemplates> list = gridCmdTemplatesService.selectGridCmdTemplatesList(gridCmdTemplates);
        return getDataTable(list);
    }

    /**
     * 导出模板管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:templates:export')")
    @Log(title = "模板管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GridCmdTemplates gridCmdTemplates)
    {
        List<GridCmdTemplates> list = gridCmdTemplatesService.selectGridCmdTemplatesList(gridCmdTemplates);
        ExcelUtil<GridCmdTemplates> util = new ExcelUtil<GridCmdTemplates>(GridCmdTemplates.class);
        util.exportExcel(response, list, "模板管理数据");
    }

    /**
     * 获取模板管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:templates:query')")
    @GetMapping(value = "/{templatesId}")
    public AjaxResult getInfo(@PathVariable("templatesId") Integer templatesId)
    {
        return AjaxResult.success(gridCmdTemplatesService.selectGridCmdTemplatesByTemplatesId(templatesId));
    }

    /**
     * 新增模板管理
     */
    @PreAuthorize("@ss.hasPermi('system:templates:add')")
    @Log(title = "模板管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GridCmdTemplates gridCmdTemplates)
    {
        return toAjax(gridCmdTemplatesService.insertGridCmdTemplates(gridCmdTemplates));
    }

    /**
     * 修改模板管理
     */
    @PreAuthorize("@ss.hasPermi('system:templates:edit')")
    @Log(title = "模板管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GridCmdTemplates gridCmdTemplates)
    {
        return toAjax(gridCmdTemplatesService.updateGridCmdTemplates(gridCmdTemplates));
    }

    /**
     * 删除模板管理
     */
    @PreAuthorize("@ss.hasPermi('system:templates:remove')")
    @Log(title = "模板管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{templatesIds}")
    public AjaxResult remove(@PathVariable Integer[] templatesIds)
    {
        return toAjax(gridCmdTemplatesService.deleteGridCmdTemplatesByTemplatesIds(templatesIds));
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('system:templates:edit')")
    @Log(title = "模板管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody GridCmdTemplates gridCmdTemplates) {
        gridCmdTemplates.setUpdateBy(getUsername());
        return toAjax(gridCmdTemplatesService.updateGridCmdTemplatesStatus(gridCmdTemplates));
    }
}
